package com.atguigu.realtime.gmallpublisher2.controller;

import com.alibaba.fastjson.JSON;
import com.atguigu.realtime.gmallpublisher2.service.OderWideService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2020/12/17 10:38
 */
@RestController
public class OrderWideController {
    @Autowired
    OderWideService service;

    // http://localhost:8070/trademark?startDt=2020-08-01&endDt=2020-09-01&limit=3
    @GetMapping("/trademark")
    public String tradeMark(String startDt, String endDt, int limit) {
        List<Map<String, Object>> tmp = service.getTMAmountString(startDt, endDt, limit);

        List<Map<String, Object>> result = new ArrayList<>();

        for (Map<String, Object> map : tmp) {

            HashMap<String, Object> r = new HashMap<>();
            r.put("x", map.get("tm_name"));
            r.put("y", map.get("amount"));
            r.put("s", 1);
            result.add(r);
        }

        return JSON.toJSONString(result);
    }
}
